package com.ssm.controller.student;

import com.ssm.controller.BaseController;
import com.ssm.entity.CourseZhanshi;
import com.ssm.entity.Selectcourse;
import com.ssm.service.CourseService;
import com.ssm.service.SelectCourseService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Controller
public class StudentMarkController extends BaseController {
    @Resource(name = "selectCourseService")
    private SelectCourseService selectCourseService;
    @Resource(name = "courseService")
    private CourseService courseService;
    // 查询
    @RequestMapping(value ="mark/query",method = RequestMethod.GET)
    public String MarkQuery(HttpSession session, Map<String,Object> map){
        List<Selectcourse> list=new ArrayList<>();
        logger.info("检查学生权限");
        String adminId=checkAdmin(session);
        if (!adminId.equals("studentId")){
            return "redirect:/";
        }
        Object o=session.getAttribute("studentId");
        List<CourseZhanshi> zhanshiList=new ArrayList<>();
        list=selectCourseService.SelectCoursebyStudentid(Integer.parseInt(o.toString()));
        for (int i=0;i<list.size();i++){
            CourseZhanshi zhanshi=new CourseZhanshi();
            Selectcourse selectcourse= list.get(i);
            zhanshi.setKechengname( courseService.Coursename(selectcourse.getCourseid()));
            if (!(selectcourse.getMark()==null)){
                zhanshi.setChengji(selectcourse.getMark().toString());
            }
            zhanshiList.add(zhanshi);
        }
        map.put("zhanshiList",zhanshiList);
        for (int i = 0; i < zhanshiList.size(); i++) {
            logger.info(zhanshiList.get(i));
        }
        return "student/mark";
    }
}
